package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.*;
	
	public class GrayAction extends AbstractAction
	{
		private var matrix:Array;
		
		public function setValue(r:Number, g:Number, b:Number):GrayAction
		{
			matrix =  [ r, g, b, 0, 0, 
						r, g, b, 0, 0,
						r, g, b, 0, 0,
						0, 0, 0, 1, 0]; 	
			return this;
		}
		
		public override function getDescription():String
		{
			return "Turn to Gray";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var ret:BitmapData = old.clone();
			var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
			ret.applyFilter(ret, ret.rect, new Point(0, 0), filter);
			return ret;
		}	
	}
}